package com.clkj.xiuzheng.controller.shangcheng;

import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.pojo.shangcheng.Identity;
import com.clkj.xiuzheng.pojo.shangcheng.Menu;
import com.clkj.xiuzheng.pojo.shangcheng.Operator;
import com.clkj.xiuzheng.pojo.shangcheng.ProductFactory;
import com.clkj.xiuzheng.pojo.shangcheng.dto.DataItem;
import com.clkj.xiuzheng.service.shangcheng.ScFactoryService;
import com.clkj.xiuzheng.service.shangcheng.ScOperatorService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/ScOperator")
@CrossOrigin
@Api(value = "/ScOperator", tags = {"Z商城后台操作员管理"})
public class ScOperatorController {

    @Autowired
    private ScOperatorService scOperatorService;

    @ApiOperation(value = "根据公司id获取操作员")
    @PostMapping("/getOperatorList")
    public Result getOperatorList(@ApiParam(name = "companyId", value = "公司id")@RequestParam Integer companyId,
                                  @ApiParam(name = "operatorName", value = "操作员姓名")@RequestParam(required = false) String operatorName,
                                  @ApiParam(name = "startTime", value = "账号开始时间")@RequestParam(required = false) String startTime,
                                  @ApiParam(name = "endTime", value = "账号结束时间")@RequestParam(required = false) String endTime,
                                  @ApiParam(name = "pageSize", value = "页大小")@RequestParam Integer pageSize,
                                  @ApiParam(name = "pageNum", value = "页码")@RequestParam Integer pageNum) {
        try {
            PageInfo factoryList = scOperatorService.getOperatorList(companyId,operatorName,startTime,endTime,pageSize,pageNum);
            return new Result(true, StatusCode.OK,"查询成功",factoryList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据公司id添加操作员")
    @PostMapping("/addOperator")
    public Result addOperator(@ApiParam(name = "companyId", value = "公司id")@RequestParam Integer companyId,
                                  @ApiParam(name = "operatorName", value = "操作员姓名")@RequestParam(required = false) String operatorName
                                 ) {
        try {
            scOperatorService.addOperator(companyId,operatorName);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据操作人id上下线操作人状态")
    @PostMapping("/updateOperatorStaus")
    public Result updateOperatorStaus(@ApiParam(name = "Ids", value = "公司id字符串")@RequestParam String Ids,
                                      @ApiParam(name = "Status", value = "0下线 1 上线")@RequestParam Integer Status) {
        try {
            scOperatorService.updateOperatorStaus(Ids,Status);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据公司id获取身份列表")
    @PostMapping("/getIdentityList")
    public Result getIdentityList(@ApiParam(name = "companyId", value = "公司id")@RequestParam Integer companyId) {
        try {
            List<Identity> list = scOperatorService.getIdentityList(companyId);
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据操作员id和身份id分配身份")
    @PostMapping("/updateIdentity")
    public Result updateIdentity(@ApiParam(name = "operatorId", value = "操作员id")@RequestParam Integer operatorId,
                                 @ApiParam(name = "identityId", value = "身份id")@RequestParam Integer identityId) {
        try {
            scOperatorService.updateIdentity(operatorId,identityId);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "获取所有菜单名单")
    @PostMapping("/getMenuListByCompanyId")
    public Result getMenuListByCompanyId() {
        try {
            List<Menu> list = scOperatorService.getMenuListByCompanyId();
            return new Result(true, StatusCode.OK,"查询成功",list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据公司id新增身份")
    @PostMapping("/addIdentity")
    public Result addIdentity(@RequestParam String  Ids,
                              @RequestParam String  identityName,
                              @RequestParam Integer companyId) {
        try {
            scOperatorService.addIdentity(Ids,identityName,companyId);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "根据公司id修改")
    @PostMapping("/updateIdentityById")
    public Result updateIdentityById(
                              @RequestParam Integer  IdentityId,
                              @RequestParam String  Ids,
                              @RequestParam String  identityName,
                              @RequestParam Integer companyId) {
        try {
            scOperatorService.updatedentity(IdentityId,Ids,identityName,companyId);
            return new Result(true, StatusCode.OK,"查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

}
